<?php
    if ($_COOKIE['LOG'] == false) {
        header('Location: ../index.php');
    }
    include_once '../config.php';

    $project_nr = $_GET['project_nr'];
    $client_id  = $_GET['client_id'];
    $sql = "SELECT * FROM project p LEFT JOIN address a ON (a.address_id = p.address_id) LEFT JOIN `client` c ON "
         . "(c.client_id = p.client_id) WHERE project_nr = '" . $project_nr . "'";
    $result = mysql_query($sql);

?>
            <div>
                <div class="toolbar">
                    <h1>A <?php echo $project_nr; ?></h1>
                    <a class="cancel flipright" href="javascript:window.location = 'index.php'">Abbrechen</a>
                </div>
                    <?php

                        if (mysql_num_rows($result) > 0) {
                            $data = mysql_fetch_array($result);
                            if ($data['get'] == 0) {
                            ?>
                                <form id="p_edit" name="p_edit" action="work/p_edit.php" method="POST" class="form">
                                    <div class="info">
                                        Euro-Beträge bitte mit einem Punkt schreiben wenn es sich um eine Kommazahl handelt! (z.B. 123.45)
                                    </div>
                                    <ul class="rounded">
                                        <li>
                                            <input type="hidden" name="p_nr" value="<?php echo $project_nr; ?>" />
                                            <input type="hidden" name="p_client_id" value="<?php echo $client_id; ?>" />
                                            <h3>Name:</h3><?php echo $data['p_name']; ?>
                                            <h3>Ort:</h3><?php echo $data['city'] ?>
                                            <h3>Auftraggeber:</h3><?php echo $data['name']; ?>
                                            <?php
                                                $datearray = explode('-', $data['date_inquiry'])
                                            ?>
                                            <h3>Datum der Anfrage:</h3><?php echo $datearray[2].'.'.$datearray[1].'.'.$datearray[0]; ?>
                                        </li>
                                    </ul>
                                    <h2>Datum des Angebots</h2>
                                    <ul class="rounded">
                                        <li><input type="date" id="p_date_offer" name="p_date_offer" value="<?php echo $data['date_offer']; ?>" />
                                    </ul>
                                    <h2>Angebotssumme</h2>
                                    <ul class="rounded">
                                        <li><input type="text" id="p_offer_sum" name="p_offer_sum" placeholder="z.B 123.45" value="<?php echo $data['offer_sum']; ?>" /></li>
                                    </ul>
                                    <h2>Kaufmann des Auftraggebers</h2>
                                        <ul class="rounded">
                                            <li>Neu Anlegen: <span class="toggle"><input type="checkbox" id="new_km_check" name="nkmc" onchange="new_km()"/></span></li>
                                        </ul>
                                    <?php
                                        $sql_two = "SELECT * FROM project_manager WHERE client_id = " . $client_id . " AND km_or_pm = 'km'";
                                        $result_two = mysql_query($sql_two);
                                    ?>
                                    <ul class="rounded" id="new_km">
                                        <li id="p_km">
                                            <select name="p_km">
                                        <?php
                                            if (mysql_num_rows($result_two) > 0) {
                                                while ($data_two = mysql_fetch_array($result_two)) {
                                        ?>
                                            <option value="<?php echo $data_two['pm_id']; ?>"><?php echo $data_two['vorname'] . " " . $data_two['name']; ?></option>
                                        <?php
                                                }
                                            } else {
                                        ?>
                                                <option>Keine Kaufmänner vorhanden</option>
                                        <?php
                                            }
                                        ?>
                                            </select>
                                        </li>
                                        <li id="km_name"style="display:none" ><input type="text" name="km_name" placeholder="Name *" /></li>
                                        <li id="km_vorname" style="display:none" ><input type="text" name="km_vorname" placeholder="Vorname" /></li>
                                        <li id="km_phone" style="display:none" ><input type="tel" name="km_phone" placeholder="Telefon" /></li>
                                        <li id="km_email" style="display:none" ><input type="email" name="km_email" placeholder="E-Mail" /></li>
                                        <li id="km_mobil" style="display:none" ><input type="text" name="km_mobil" placeholder="Mobil" /></li>
                                    </ul>
                                    <h2>Bemerkung</h2>
                                    <ul class="rounded">
                                        <li><textarea placeholder="Kommentar eintragen!" name="p_comment"><?php echo $data['comment']; ?></textarea></li>
                                    </ul>
                                    <h2>Auftrag erhalten?</h2>
                                    <ul class="rounded">
                                        <li>
                                            <select name="choose">
                                                <option value="0">Noch offen</option>
                                                <option value="1">Angenommen</option>
                                                <option value="2">Abgelehnt</option>
                                            </select>
                                        </li>
                                    </ul>
                                    <a href="#" style="margin: 10px;" class="grayButton submit">Änderungen speichern</a>
                                </form>
                            <?php
                            } else if ($data['get'] == 1) {

                            } else {

                            }
                        }

                   ?>
            </div>